package com.sfh.cp.widget;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * 功能描述:可设置是否滑动ViewPager
 *
 * @author SunFeihu 孙飞虎
 * @date 2016/11/15
 */

public class WidgetViewPager extends ViewPager {
    private boolean isForbidScroll;

    public WidgetViewPager(Context context) {
        super(context);
    }

    public WidgetViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void setForbidScroll(boolean value) {
        isForbidScroll = value;
    }

    public boolean isForbidScroll() {
        return isForbidScroll;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        return isForbidScroll() ? false : super.onTouchEvent(ev);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return isForbidScroll() ? false : super.onInterceptTouchEvent(ev);
    }
}
